{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>用户持券列表</legend>
    </fieldset>

    <blockquote class="layui-elem-quote layui-clear">
        <div class="demoTable layui-row layui-input-4">
            <div class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户手机号</label>
                    <div class="layui-input-inline layui-form">
                        <input class="layui-input" name="phone" id="phone" placeholder="请输入用户手机号">
                    </div>
                </div>
            </div>
        </div>
        <div class="demoTable layui-row layui-input-4">
            <div class="layui-form layui-form-pane" >
                <div class="layui-form-item">
                    <label class="layui-form-label">订单编号</label>
                    <div class="layui-input-inline layui-form">
                        <input class="layui-input" name="upgrade_number" id="upgrade_number" placeholder="请输入订单编号">
                    </div>
                </div>
            </div>
        </div>
        <div class="demoTable layui-row layui-input-4">
            <div class="layui-form layui-form-pane" >
                <div class="layui-form-item">
                    <label class="layui-form-label">订单状态</label>
                    <div class="layui-input-inline layui-form">
                        <select name="status" lay-filter="interest-search" lay-search placeholder="请选择订单状态"
                            id="status">
                            <option value="-1">请选择订单状态</option>
                            <option value="0">未付款</option>
                            <option value="1">已付款</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="demoTable layui-row layui-input-4">
            <button class="layui-btn" style="margin-left:30px;margin-top:7px" id="search"
                data-type="reload">{:lang('search')}</button>
            <a href="{:url('order')}" style="margin-top:7px" class="layui-btn">{:lang('reset')}</a>
        </div>
    </blockquote>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="avatarUrl">
	<img src="{{d.avatar}}" style="width:40%;height:100%;"/>
</script>
<script type="text/html" id="eqimgUrl">
	<img src="{{d.eqimg}}" style="width:40%;height:100%;"/>
</script>

<script type="text/html" id="open">
	{{# if(d.status==0){ }}
        未付款
    {{# }else{ }}
        已付款
    {{# }}}
</script>

<script type="text/html" id="sex">
    {{# if(d.sex == 1){  }}
        男
    {{# }else if(d.sex == 2){   }}
        女
    {{# }else{ }}
        保密
    {{# } }}
</script>
<script type="text/html" id="action">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
</script>

<script>

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //日期时间范围
        laydate.render({
            elem: '#test10'
            , type: 'datetime'
            , range: true
        });
    })
    layui.use(['table', 'form'], function () {
        var table = layui.table, form = layui.form, $ = layui.jquery;
        var tableIn = table.render({
            id: 'ad',
            elem: '#list',
            url: '{:url("order")}',
            method: 'post',
            page: true,
            cols: [[
                { field: 'id', align: 'center', title: '{:lang("id")}', width: 80, fixed: true, sort: true },
                { field: 'recharge_number', align: 'center', title: '订单编号', width: 200 },
                { field: 'realname', align: 'center', title: '真实姓名', width: 150 },
                { field: 'phone', align: 'center', title: '手机号', width: 150 },
                { field: 'vip_number', align: 'center', title: '会员卡号', width: 150 },
                { field: 'title', align: 'center', title: '充值卡', width: 130, },
                { field: 'money', align: 'center', title: '订单价格', width: 150 },
                { field: 'status', align: 'center', title: '订单状态', width: 100, toolbar: '#open' },
                { field: 'addtime', align: 'center', title: '创建时间', width: 150 },
                // { width: 160, align: 'center', title: '{:lang("action")}', toolbar: '#action', fixed:'right'}
            ]],
            limit: ''
        });
        //搜索
        $('#search').on('click', function () {
            var phone = $('#phone').val();
            let upgrade_number = $('#upgrade_number').val()
            let status = $('#status').val();
            //alert(addtime);
            if ($.trim(phone) === '' && $.trim(status) === -1 && upgrade_number==='') {
                layer.msg('{:lang("query_condition")}', { icon: 0 });
                return;
            }
            let where = { phone: phone, status: status == -1 ? '' : status,upgrede_number:upgrade_number }
            if (status == -1) {
                delete where.status
            }
            tableIn.reload({
                where: where
            });
        });

        //点击table上的按钮
        table.on('tool(list)', function (obj) {
            //获取当前点击行的数据
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定要删除该数据吗！', function (index) {
                    var loading = layer.load(1, { shade: [0.1, '#fff'] });
                    $.post("{:url('orderDel')}", { id: data.id }, function (res) {
                        layer.close(loading);
                        if (res.errorCode == 8888) {
                            layer.msg(res.msg, { time: 1000, icon: 1 });
                            obj.del();
                        } else {
                            layer.msg(res.msg, { time: 1000, icon: 2 });
                        }
                    });
                    layer.close(index);
                });
            }
        });
    })
</script>